<template>
  <div class="login">
    <div class="beijing"></div>
    <div class="neirong">
      <el-form
          ref="loginForm"
          :model="loginForm"
          :rules="loginRules"
          class="login-form"
      >
        <div style="padding: 25px 25px 5px 25px;">
          <div style="font-size: 34px; font-weight: Bold;margin: 0 0 5px 0;color: #4259A5;width: 100%;">您好！</div>
          <div style="font-size: 18px; font-weight: 500;margin: 0 0 20px 0;color: #333333;width: 100%;">欢迎登录宁阳安全生产数字化监管预警系统</div>
          <el-form-item prop="username">
            <el-input
                v-model="loginForm.username"
                type="text"
                auto-complete="off"
                placeholder="请输入用户名"
            >
              <span slot="prefix" class="input_title" style="width: 42px;">用户名</span>
            </el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
                v-model="loginForm.password"
                type="password"
                auto-complete="off"
                placeholder="请输入密码"
                @keyup.enter.native="handleLogin"
            >
              <span slot="prefix" class="input_title" style="width: 30px;">密码</span>
            </el-input>
          </el-form-item>
<!--          <el-form-item prop="code">-->
<!--            <el-input-->
<!--                v-model="loginForm.code"-->
<!--                auto-complete="off"-->
<!--                placeholder="请输入验证码"-->
<!--                style="width: 63%"-->
<!--                @keyup.enter.native="handleLogin"-->
<!--            >-->
<!--              <span slot="prefix" class="input_title" style="width: 42px;">验证码</span>-->
<!--            </el-input>-->
<!--            <div class="login-code">-->
<!--              <img :src="codeUrl" @click="getCode" class="login-code-img" />-->
<!--            </div>-->
<!--          </el-form-item>-->
          <el-form-item style="width: 100%">
            <el-button
                :loading="loading"
                size="medium"
                type="primary"
                style="width: 114px;height: 40px;float: left;background-color: #F29933;border: 1px solid #F29933;"
                @click.native.prevent="handleLogin"
            >
              <span v-if="!loading">登 录</span>
              <span v-else>登 录 中...</span>
            </el-button>
          </el-form-item>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import {getInfo, Login} from "@/api/login";

export default {
  name: "Login",
  data() {
    return {
      codeUrl: "",
      loginForm: {
        username: "",
        password: "",
        // code: "",
        uuid: "",
      },
      loginRules: {
        username: [
          { required: true, trigger: "blur", message: "请输入您的账号" },
        ],
        password: [
          { required: true, trigger: "blur", message: "请输入您的密码" },
        ],
        // code: [{ required: true, trigger: "change", message: "请输入验证码" }],
      },
      loading: false,
    };
  },
  created() {
    // this.getCode()
  },
  methods: {
    // getCode() {
    //   getCodeImg().then(res => {
    //     this.captchaEnabled = res.data.captchaEnabled === undefined ? true : res.data.captchaEnabled;
    //     if (this.captchaEnabled) {
    //       this.codeUrl = "data:image/gif;base64," + res.data.img;
    //       this.loginForm.uuid = res.data.uuid;
    //     }
    //   });
    // },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true;
          Login(this.loginForm).then(res => {
            if (res.status == 200) {
              if (res.data.code == 200) {
                this.$message({
                  message: '登录成功！',
                  type: 'success'
                });
                localStorage.setItem("token", res.data.token)
                getInfo().then(rs => {
                  localStorage.setItem("companyId", rs.data.user.companyId)
                  localStorage.setItem("roles", rs.data.roles.join())
                  if (rs.data.roles.join() == "head"){
                    this.$router.push("/enterprise")
                  }else {
                    this.$router.push("/")
                  }
                })
              } else {
                this.$message.error(res.data.msg);
                this.loading = false;
                if (this.captchaEnabled) {
                  this.getCode();
                }
              }
            }
          })
        }
      });
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.neirong {
  z-index: 5;
}
.beijing {
  background-image: url("../../assets/image/logoback-image.png");
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0px;
  top: 0px;
  background-repeat: no-repeat;
  background-size: 100% 105%;
  background-position: center;
  -webkit-filter: blur(10px);
  -moz-filter: blur(10px);
  -o-filter: blur(10px);
  -ms-filter: blur(10px);
  filter: blur(1px);
}
.login {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
}
.title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #707070;
}

.login-form {
  float: left;
  background: #ffffff;
  width: 400px;
  .el-input {
    height: 38px;
    input {
      height: 38px;
    }
  }
  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 2px;
  }
}
.login-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}
.login-code {
  width: 33%;
  height: 38px;
  float: right;
  img {
    cursor: pointer;
    vertical-align: middle;
  }
}
.el-login-footer {
  background-color: #F5F5F5;
  color: #999999;
  text-align: center;
  height: 2rem;
  line-height: 2rem;
  width: 100%;
  font-family: Source Han Sans CN-Regular, Source Han Sans CN;
  font-size: 12px;
  font-weight: 400;
}
.login-code-img {
  height: 38px;
}

.input_title{
  padding: 0px 3px;
  line-height: 0;
  height: 2px;
  text-align: left;
  margin-left: 15px;
  margin-top: 0px;
  color: rgb(153, 153, 153);
  font-size: 12px;font-weight: 400;
  position: absolute;background-color: rgb(255, 255, 255);
}
</style>

<style  lang="postcss" scoped>
/deep/.el-checkbox__input.is-checked .el-checkbox__inner{
  background-color: #4259a5;
  border-color: #4259a5;
}
/deep/.el-form-item{
  margin-bottom: 25px;
}
/*/deep/.el-form-item__error{*/
/*  margin-left: 96px;*/
/*  margin-top: -42px;*/
/*}*/
/*/deep/.el-form-item__error:nth-child(3){*/
/*  margin-left: 96px;*/
/*  margin-top: -21px;*/
/*}*/
</style>
